#! /usr/bin/perl -w
use strict;

# =====================================================================================
#
#       Filename:  CompileLogAnalysis 
#
#    Description:  Generate List For Compile Error Log.
#
#          Input:  The path of the log file 
#                  eg: ./CompileLogAnalysis build_20111221011048.log
#         
#         Output:  CompileErrorProgram.lst
#           
#        Version:  1.0
#        Created:  2011/12/27 09:45:26
#       Revision:  1
#
#         Author:  Wade Xu (jxx), jxx@qad.com
#                   Copyright 1986-2011 QAD Inc., Santa Barbara, CA, USA. 
#
# =====================================================================================


# Global Variable Definitions
our @lines;

# Main Routine
if (@ARGV == 0)
{
    print "Please input the path of the log file.\n";
    print "eg: ./CompileLogAnalysis build_20111221011048.log\n";
}
else
{
    print "\nBegin Processing $ARGV[0] ......\n";

    open (SOURCEFILE, $ARGV[0])
        || die "Cannot open file $ARGV[0].";
    @lines = <SOURCEFILE>;

    open (OUTFILE, ">CompileErrorProgram.lst");
    print OUTFILE ("PROGRAM\t\t\t\t\tERROR FILE\t\t\tERROR Line & Column\n");
    print OUTFILE ("-------------  -------------------  ----------------------------------\n");

    my $line;
    foreach $line(@lines)
    {
        if ( $line =~ /Error compiling file (.*)\.r in included file .*\/src\/us\/(.*) at line (.*) column (.*)/ )
        {
            printf OUTFILE ("%14s\t%18s\t%30s\n","$1.p",$2,"line $3 column $4");
        }
    }
    close OUTFILE;
    close SOURCEFILE;

    print "End $ARGV[0]......\n\n";
}
